package com.zb.zeus.common.core.web.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Oracle表的Entity基类
 *
 * @author zb.zeus
 */
@Data
public class OracleEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "主键")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @TableField(value = "create_by", fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建人ID")
    protected String createBy;

    @TableField(value = "create_name", fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建人名称")
    protected String createName;

    /**
     * 创建时间 (from ihr)
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected Date createTime;

    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(value = "修改人AD")
    protected String updateBy;

    @TableField(value = "update_name", fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(value = "修改人名称")
    protected String updateName;

    /**
     * 更新时间 (from ihr)
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(value = "修改时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected Date updateTime;

    @TableLogic
    @ApiModelProperty(value = "删除标记 0:未删除;1:已删除")
    @TableField(value = "dr", fill = FieldFill.INSERT)
    protected Integer dr;


    @Version
    @TableField(value = "edition", fill = FieldFill.INSERT, update = "%s+1")
    @ApiModelProperty(value = "乐观锁")
    protected Integer edition;

    /**
     * 搜索值
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "搜索值")
    private String searchValue;


    /**
     * 请求参数
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "请求参数")
    private Map<String, Object> params = new LinkedHashMap<>();

    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
